import { createStore } from 'vuex'
import cart from './modules/cart'
import payment from './modules/payment'
import review from './modules/review'
import shipping from './modules/shipping'

export default createStore({
  state: {
    user: null,
    token: localStorage.getItem('token') || ''
  },
  mutations: {
    SET_USER(state, user) {
      state.user = user
    },
    SET_TOKEN(state, token) {
      state.token = token
      localStorage.setItem('token', token)
    }
  },
  actions: {
    logout({ commit }) {
      commit('SET_USER', null)
      commit('SET_TOKEN', '')
      localStorage.removeItem('token')
    }
  },
  modules: {
    cart,
    payment,
    review,
    shipping
  }
}) 